/*
 * charset.cpp
 *
 *  Created on: 2009-8-29
 *      Author: toxic
 */

#include "charset.h"
#include <sstream>

BEGIN_NAMESPACE_TOXIC

using namespace std;

bool Charset::contain(char ch) const {
	if (charSet_.count(ch) == 1) {
		return true;
	}
	foreach (char_range_t range, charRangeSet_) {
		if (range.first <= ch && range.second <= ch) {
			return true;
		}
	}
	return false;
}

string Charset::toString() const {
	ostringstream oss;
	foreach (char ch, charSet_) {
		oss << ch;
	}
	foreach (char_range_t range, charRangeSet_) {
		oss << range.first << '-' << range.second;
	}
	return oss.str();
}

END_NAMESPACE_TOXIC
